const app = getApp()

import util from '../../../utils/util'
import {
  EdiList
} from '../../../config/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    limit: 10,
    list: [],
    isEmpty: false, // 是否为空
    isBottom: false, // 是否无数据触底了
    isReachBtm: false, // 是否触发上拉加载
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getList()
  },

  getList() {
    let that = this;
    let member = wx.getStorageSync("member");
    let params = {
      uid: member.id,
      vollege_id: member.vollege_id,
      page: this.data.page,
      limit: this.data.limit
    }
    util.apiRequest(EdiList, params, null).then(r => {
      console.log("列表：", r)
      var newList = that.data.list.concat(r.data.data)
      if (r.data.data.length == 0 && that.data.isReachBtm == true) {
        that.setData({
          isBottom: true
        })
        wx.showToast({
          title: '暂无更多',
          icon: 'none',
        })
      }
      that.setData({
        list: newList
      })
      if (newList.length == 0) {
        that.setData({
          isEmpty: true
        })
      } else {
        that.setData({
          isEmpty: false
        })
      }
      wx.hideLoading();
    })
  },

  toDetail(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/new_index/convenient_service/endowment_insurance/endowment_insurance?id='+id,
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    var page = this.data.page;
    that.setData({
      isReachBtm: true
    })
    if (that.data.isBottom) return;
    page++;
    that.setData({
      page
    })
    console.log('page++', page)
    this.getList()
},

/**
 * 用户点击右上角分享
 */
onShareAppMessage: function() {

}
})